package com.lupan.passwordbox.controller;

import com.lupan.passwordbox.common.base.Response;
import com.lupan.passwordbox.domain.Account;
import com.lupan.passwordbox.service.AccountService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 说明：
 *
 * @author lupan
 * @version 2017/8/18 14:54
 */
@RestController
@Api(value = "AccountController", description = "账户操作")
@RequestMapping("account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @ApiOperation("根据id获取账户")
    @RequestMapping(value = "get", method = RequestMethod.GET)
    public Response get(@NotNull long id) {
        Account account = accountService.get(id);
        return Response.create(account);
    }

    @ApiOperation("根据用户名、密码获取账户")
    @RequestMapping(value = "getByNameAndPassword", method = RequestMethod.GET)
    public Response get(String username, String password) {
        List<Account> list = accountService.get(username, password);
        return Response.create(list);
    }

    @RequestMapping(value = "add", method = RequestMethod.POST)
    public Response add(@RequestBody Account account) {
        accountService.add(account);
        return Response.create("success");
    }
}
